package com.niit.onlinemusic.controller;

import com.niit.onlinemusic.common.R;
import com.niit.onlinemusic.service.CommentService;
import org.springframework.web.bind.annotation.*;

/**
 * 评论控制器
 *
 * @author zuwei522
 * @since 2025/9/27 23:29
 */
@RestController
@RequestMapping("comment")
public class CommentController {

    private final CommentService commentService;

    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    /**
     * 根据歌单ID查询评论
     *
     * @param songListId 歌单ID
     * @return 评论列表
     * @author zuwei522
     * @since 2025/9/27 23:41
     */
    @GetMapping("songList/{songListId}")
    public R getCommentBySongListId(@PathVariable("songListId") Integer songListId) {
        return commentService.getCommentBySongListId(songListId);
    }

    /**
     * 删除评论
     *
     * @param id 评论ID
     * @return R
     * @author zuwei522
     * @since 2025/9/27 23:54
     */
    @GetMapping("delete")
    public R deleteComment(@RequestParam("id") Integer id) {
        if (commentService.removeById(id)) {
            return R.success("删除成功");
        } else {
            return R.error("删除失败");
        }
    }

}
